package com.dy.lock.screen.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.dy.lock.screen.dao.CustomerTagDao;
import com.dy.lock.screen.pojo.CustomerTagRelation;
import com.dy.lock.screen.service.CustomerTagService;

@Service("customerTagService")
public class CustomerTagServiceImpl implements CustomerTagService {

	@Resource(name = "customerTagDao")
	private CustomerTagDao customerTagDao;

	@Override
	public List<CustomerTagRelation> getCustomerTags(String customerId) {
		return this.customerTagDao.queryByCustomerId(customerId);
	}

	@Override
	public Boolean updateCustomerTags(String customerId, List<String> tags) {
		CustomerTagRelation t = new CustomerTagRelation();
		t.setCustomerId(customerId);
		this.customerTagDao.delete(t);

		for (String tagId : tags) {
			String id = "";
			String maxId = this.customerTagDao.queryMaxId();
			if (StringUtils.isBlank(maxId)) {
				id = "10000000";
			} else {
				id = String.valueOf(Integer.parseInt(maxId) + 1);
			}
			t.setId(id);
			t.setAdTagId(tagId);
			int re = this.customerTagDao.insert(t);
			if (re == 0) {
				return false;
			}
		}
		return true;
	}

	@Override
	public List<String> queryTagByCustomerId(String customerId) {
		// TODO Auto-generated method stub
		return this.customerTagDao.queryTagByCustomerId(customerId);
	}

}
